cd ""
*use "data_figure_4.dta", clear
import delimited "data_figure_4.txt", clear 

gen zone2="NE" if st=="ME" | st=="NH" | st=="VT" | st=="MA" | st=="RI" | st=="CT" 
replace zone2="MA" if st=="NY" | st=="NJ" | st=="PA" 
replace zone2="ENC" if st=="OH" | st=="IN" | st=="IL" | st=="MI" | st=="WI"  
replace zone2="WNC" if st=="MN" | st=="IA" | st=="MO" | st=="ND" | st=="SD" | st=="NE" | st=="KS" 
replace zone2="SA" if st=="DE" | st=="MD" | st=="DC" | st=="VA" | st=="WV" | st=="NC" | st=="SC" | st=="GA" | st=="FL"  
replace zone2="ESC" if st=="KY" | st=="TN" | st=="AL" | st=="MS"  
replace zone2="MNT" if st=="MT" | st=="ID" | st=="WY" | st=="CO"  | st=="NM" | st=="AZ" | st=="UT" | st=="NV" 
replace zone2="PA" if st=="WA" | st=="CA" | st=="OR" 
replace zone2="WSC" if st=="AR" | st=="TX" | st=="OK" | st=="LA" 
encode zone2, gen(zz)

gen cars_p=cars/popula
gen ld_p=log(a_totdep)-log(popula)


tsset ss year
char year[omit] 1934

gen coef_car=. 
gen coef_depo =.
gen sd_car =.
gen sd_depo =.

xi: reghdfe cars_p i.year*radio lincome_pc dtoty_pc  c.year#c.vet c.year#c.toty30pc   if year>1929 & year<=1939 ,absorb(ss  zz#year  ) cluster(ss )
matrix A=e(b)
matrix B=e(V)

forval i=11(1)14 {


replace coef_car=A[1,`i']  if year==1919+`i' 
replace sd_car=sqrt(B[`i',`i'])  if year==1919+`i'


}
replace coef_car=0 if year==1934
replace sd_car=0 if year==1934
forval i=15(1)19 {


replace coef_car=A[1,`i']  if year==1920+`i' 
replace sd_car=sqrt(B[`i',`i'])  if year==1920+`i'


}

xi: reghdfe ld_p i.year*radio lincome_pc dtoty_pc c.year#c.vet c.year#c.toty30pc  if year>1929 & year<=1939 ,absorb(ss zz#year ) cluster(ss )  


matrix A=e(b)
matrix B=e(V)


forval i=11(1)14 {


replace coef_depo=A[1,`i']  if year==1919+`i' 
replace sd_depo=sqrt(B[`i',`i'])  if year==1919+`i'


}
replace coef_depo=0 if year==1934
replace sd_depo=0 if year==1934
forval i=15(1)19 {


replace coef_depo=A[1,`i']  if year==1920+`i' 
replace sd_depo=sqrt(B[`i',`i'])  if year==1920 +`i'


}

gen upperb_car5=coef_car+1.96*sd_car
gen lowerb_car5=coef_car-1.96*sd_car

gen upperb_car=coef_car+1.65*sd_car
gen lowerb_car=coef_car-1.65*sd_car

gen upperb_depo5=coef_depo+1.96*sd_depo
gen lowerb_depo5=coef_depo-1.96*sd_depo

gen upperb_depo=coef_depo+1.65*sd_depo
gen lowerb_depo=coef_depo-1.65*sd_depo

graph twoway  (rspike lowerb_car5 upperb_car5 year, color(gs12) mcolor(0)) (rcap lowerb_car upperb_car year, color(gs0) lwidth(medium) )  ///
 (scatter coef_car year, color(gs0))if year<1940 & year>1929,  xline(1934.5 , lcolor(black)) name(a1, replace) legend( label(1 "90%")  label(3 "Coefficient") label(2 "95%")  rows(1) order(3 2 1 ) ) ///
 title(Car Sales per capita (logs), color(black)) ytitle(Cars per capita) xtitle("") yline(0, lcolor(black)) ///
  graphregion(color(white)) ysc(r(-0.03 0.03)) ylabel(-0.03(0.01)0.03) 

graph twoway  (rspike lowerb_depo5 upperb_depo5 year, color(gs12) mcolor(0)) (rcap lowerb_depo upperb_depo year, color(gs0) lwidth(medium) )  ///
 (scatter coef_depo year, color(gs0))if year<1940 & year>1929,  xline(1934.5, lcolor(black)) name(a2, replace) legend( label(1 "90%")  label(3 "Coefficient") label(2 "95%")  rows(1) order(3 2 1 ) ) ///
 title(Deposits per capita (logs), color(black)) ytitle(Log Deposits) xtitle("") yline(0, lcolor(black)) ///
  graphregion(color(white)) ysc(r(-1.5 1.5)) ylabel(-1.5(0.5)1.5) 


